<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>

<link rel="stylesheet" type="text/css" href="js/bootstarp-3.3.7/css/bootstrap.min.css" />
	<script src="js/jquery-3.2.0.min.js" type="text/javascript" charset="utf-8"></script>
	<script src="js/bootstarp-3.3.7/js/bootstrap.min.js" type="text/javascript" charset="utf-8"></script>
	<link rel="stylesheet" type="text/css" href="js/bootstarp-table-1.11.1/bootstrap-table.min.css" />
	<script src="js/bootstarp-table-1.11.1/bootstrap-table.min.js" type="text/javascript" charset="utf-8"></script>
	<script src="js/bootstarp-table-1.11.1/bootstrap-table-zh-CN.min.js" type="text/javascript" charset="utf-8"></script>
		
		 
		
    <script type="text/javascript">
    $(function() {
    	$("#tab").bootstrapTable({
    		url:"shgl/cx.lgg",
			pagination:true,
			pageSize:5, 
			queryParams:queryParam,
            columns:[{	
				field:'rcpt_id',
				title:'收货单号',
			    align:'center'
			},{
				field:'plan_receipt_date',
				title:'预计入库时间',
			    align:'center'
			},{
				field:'status_id',
				title:'状态',
			    align:'center'
			},{
				field:'rcpt_id',
				title:'收货操作',
			    align:'center',
			     formatter:function (value,row,index) {
						return"<button class='btn btn-info glyphicon glyphicon-edit' onclick='sh("+row.rcpt_id+")'></button>"
				    }
			},{
				field:'',
				title:'指定库位',
			    align:'center',
			     formatter:function (value,row,index) {
						return"<button class='btn btn-warning glyphicon glyphicon-plus' onclick='zdkw("+row.rcpt_id+")'></button>"
				    }
			},{
				field:'rcpt_id',
				title:'入库确认',
			    align:'center',
			     formatter:function (value,row,index) {
						return"<button class='btn btn-danger glyphicon glyphicon-check' onclick='qr("+row.rcpt_id+")'></button>"
				    }
			}
			]
    	})
    	
    
    	
    	
    	
    	 $("#tab7").bootstrapTable({
				url:"shgl/yrk.lgg",
				pagination:true,
				pageSize:5, 
				queryParams:{},				
				columns:[{
					field:'prod_id',
					title:'货物编号',
				    align:'center'
				},{
					field:'pname',
					title:'货物名称',
				    align:'center'
				},{
					field:'pcode',
					title:'货物编码',
				    align:'center'
				},{
					field:'ptype',
					title:'货物型号',
				    align:'center'
				},{
					field:'package_name',
					title:'包装单位',
					align:'center'
				},{
					field:'lostcount',
					title:'预出库数量',
					align:'center'
				},{
					field:'done_flag',
					title:'出库确认',
					align:'center'
				},{
					title:'删除',
				    align:'center',
				    formatter:function (value,row,index) {
						return"<button class='btn btn-danger' onclick='delet("+row.preind+","+row.lostcount+","+row.rcpt_prod_id+")'><span class='glyphicon glyphicon-trash' aria-hidden='true'></span></button>"
				    }
				}]
			})
  
    	
		$.ajax({
			type: "post",
			url: "shgl/so.lgg",
			success: function(data) {
//				alert(data.wh_id);
						
				for(i = 0; i < data.length; i++) {
					alert(data[i].whId)
					$("#name").append("<option value='" + data[i].whId + "'>" + data[i].name + "</option>")
				}
			     }
		     });
				
				
			$("#btn").click(function(){
//		     alert($("#name").val())
			 $("#tab").bootstrapTable('refresh');
		})
	
    })
    
    
 
    
    
    
      	
	 function delet(preind,lostcount,rcpt_prod_id){  
// 	     alert("确定删除此条数据吗?")
   	     $.ajax({
          	  type:"post",
          	  url:"shgl/dele.lgg",
              data:"preind="+preind+"&lostcount="+lostcount+"&rcpt_prod_id="+rcpt_prod_id,
          	  success:function (data) {
          		$("#tab7").bootstrapTable('refresh');
          	 	$("#tab6").bootstrapTable('refresh'); 
          	 }
         });  
    }
			
    
    function queryParam(){
			return{
			'wh_id':$("#name").val(),
			
			}
			
		}
    	
    	
    function sh(rcpt_id){
    	$("#myModal").modal('show');
    	$("#tab2").bootstrapTable("destroy");
    	$("#tab2").bootstrapTable({
    		    url:"shgl/mxb.lgg",
				queryParams:"rcpt_id="+rcpt_id,
				columns:[{
					field:'pname',
					title:'货物名称',
					align:'center'
				},{
					field:'pcode',
					title:'货物编码',
					align:'center'
				},{ 
					field:'ptype',
					title:'货物型号',
					align:'center'
				},{
					field:'plan_amt',
					title:'计划数量',
					align:'center'
				},{
					field:'packname',
					title:'包装单位',
					align:'center'
				},{
					field:'incount', 
					title:'实收数量',
					align:'center', 
					formatter:function (value,row,index) { 
				    	return '<input type="text"  class="form-control number1" style="width:60px" value="0" >'
			         }			
				},{
					field:'lostcount',
					title:'丢失数量',
					align:'center',
					formatter:function (value,row,index) { 
				    	return '<input type="text"  class="form-control number2" style="width:60px" value="0" >' 
			         }
				},{
				    field:'destorycount',
					title:'货损数量',
					align:'center',
					formatter:function (value,row,index) { 
				    	return '<input type="text" class="form-control number3" style="width:60px" value="0">' 
			         }
				},{
				    field:'rcpt_prod_id', 
					title:'操作',
					align:'center',
					 formatter:function (value,row,index) {
							return"<button class='btn btn-warning glyphicon glyphicon-check' onclick='xg("+row.rcpt_prod_id+","+index+")'></button>"
					    }
				},{
					field:'prod_id',
					title:'货损录入',
					align:'center',
					 formatter:function (value,row,index) {
							return"<button class='btn btn-info glyphicon glyphicon-edit' onclick='prolr("+row.prod_id+")'></button>"
					    }
				}
				]
				
    	})
    }
    
    
    function xg(rcpt_prod_id,index){
    	
    	 var incount =$(".number1:eq("+index+")").val();
         var lostcount=$(".number2:eq("+index+")").val();
         var destorycount=$(".number3:eq("+index+")").val();

		$.ajax({
        	type:"post",
        	url:"shgl/xgsj.lgg", 
        	data:"rcpt_prod_id="+rcpt_prod_id+"&incount="+incount+"&lostcount="+lostcount+"&destorycount="+destorycount,
        	success:function (data) {
        		
        		$("#tab2").bootstrapTable("refresh");
        	} 
        });  
    	
    }
    
    function prolr(prod_id){
 	
    	$("#myModal").modal('hide');
    	$("#mModal").modal('show');
    	 $("#tab4").bootstrapTable("destroy"); 
    	$("#tab4").bootstrapTable({
    		url:"shgl/hs.lgg",
			queryParams:"prod_id="+prod_id,
				columns:[{
					field:'pname',
					title:'货物名称',
					align:'center'
				},{
					field:'pcode',
					title:'货物编码',
					align:'center'
				},{
					field:'ptype',
					title:'货物型号',
					align:'center'
				},{
					field:'bar_code',
					title:'条形码',
					align:'center',
					formatter:function (value,row,index) { 
				    	return '<input type="text" id="bar_code" class="form-control number" style="width:200px" value="">'
			         }
				},{
					field:'damage_degree',
					title:'货损程度', 
					align:'center',
					formatter:function (value,row,index) { 
				    	return '<input type="text" id="damage_degree" class="form-control number" style="width:200px" value="">'
			         }
				},{
					field:'damageid',
					title:'操作',
					align:'center',
					formatter:function (value,row,index) {
					  return"<button class='btn btn-info glyphicon glyphicon-edit'  onclick='sel("+row.rcpt_id+","+row.prod_id+")'></button>"
				     } 
				 	 
				}
				]
    	})
    	
    	
    	 $("#tab5").bootstrapTable("destroy"); 
    	$("#tab5").bootstrapTable({
    	    url:"shgl/getDam.lgg",
    	    pagination:true,
			pageSize:3, 
    	    queryParams:"prod_id="+prod_id,
			columns:[{
					field:'pname',
					title:'货物名称',
					align:'center'
				},{
					field:'pcode',
					title:'货物编码',
					align:'center'
				},{
					field:'ptype',
					title:'货物型号',
					align:'center'
				},{
					field:'bar_code',
					title:'条形码',
					align:'center',
				},{
					field:'damage_degree',
					title:'货损程度',
					align:'center',
				
				},{
				    field:'damageid', 
					title:'操作',
					align:'center',
					formatter:function (value,row,index) {
						return"<button class='btn btn-danger glyphicon glyphicon-trash' onclick='qd1("+row.damageid+")'></button>"  
				   } 
				 	 
				}
				]
    	})
    	
    }
    
    
    function qd1(damageid){

    	$.ajax({
        	type:"post",
        	url:"shgl/delhsb.lgg", 
        	data:"damageid="+damageid,
        	success:function (data) {

        		$("#tab5").bootstrapTable("refresh");
        	} 
        });  
    	  
    }

    function sel(rcpt_id,prod_id){
    	
        var bar_code =($("#bar_code").val()); 
        var damage_degree=($("#damage_degree").val());
    	$.ajax({
        	type:"post",
        	url:"shgl/upSome.lgg", 
        	data:"rcpt_id="+rcpt_id+"&prod_id="+prod_id+"&bar_code="+$("#bar_code").val()+"&damage_degree="+$("#damage_degree").val() ,
        	success:function (data) {
        		$("#tab4").bootstrapTable("refresh");
        		$("#tab5").bootstrapTable("refresh");
        	} 
        });  
    	  

    }
    
    
    
    
    function zdkw(rcpt_id){
    	$("#mModal1").modal('show');
    	$("#tab6").bootstrapTable("destroy"); 
    	$("#tab6").bootstrapTable({
    		     url:"shgl/mx.lgg",
				queryParams:"rcpt_id="+rcpt_id, 
				columns:[{
					field:'pname',
					title:'货物名称',
					align:'center'
				},{
					field:'pcode',
					title:'货物编码',
					align:'center'
				},{
					field:'ptype',
					title:'货物型号',
					align:'center'
				},{
					field:'package_name',
					title:'包装单位',
					align:'center'
				},{
					field:'plan_amt',
					title:'计划数量',
					align:'center'
				},{
					field:'lostcount',
					title:'剩余数量',
					align:'center'
				},{
					field:'prein_amt',
					title:'已预留数量',
					align:'center',
				},{
					field:'in_amt',
					title:'预留数量',
					align:'center',
					formatter:function (value,row,index) {
				    	return '<form class="form-inline"><button type="button"  class="btn btn-danger addBtn glyphicon glyphicon-plus" onclick="add(' + row.lostcount + ','+index+')" ></button>  <input type="text"  class="form-control number" style="width:60px" onblur="num(' + row.lostcount + ','+index+')" value="0">  <button type="button" class="btn btn-success glyphicon glyphicon-minus reduceBtn"  onclick="reduce(' + row.lostcount + ','+index+')" ></button></form>'
				    }
				},{
					field:'rcpt_prod_id',
					title:'确认',
					align:'center',
					  formatter:function (value,row,index) {
							return"<button class='btn btn-info' onclick='up("+row.rcpt_prod_id+","+index+","+row.lostcount+","+row.in_amt+","+row.rcpt_id+")'><span class='glyphicon glyphicon-ok' aria-hidden='true'></span></button>"
					    }
				}
				]
    	})
    }
    
    
 function up(rcpt_prod_id,index,lostcount,in_amt,rcpt_id){
        alert("确定入库数量？")

		
 if ($(".number:eq("+index+")").val()!=0) { 
	$.ajax({
       	type:"post",
       	url:"shgl/upda.lgg",
       	data:"rcpt_prod_id="+rcpt_prod_id+"&lostcount="+lostcount+"&in_amt="+$(".number:eq("+index+")").val()+"&rcpt_id="+rcpt_id,
       	success:function (data) {   
       		alert(data);
       		$("#tab6").bootstrapTable("refresh");
       		$("#tab7").bootstrapTable("refresh");
       	}
       });  
 } else{
	alert("预入库数量不能等于0")
} 
 }
    
    
	function num(lostcount,index) {
		var out_amt2 = $(".number:eq("+index+")").val();
		if(out_amt2 > lostcount) {
			out_amt2 = lostcount;
			$(".addBtn:eq("+index+")").attr("disabled", "disabled");
			$(".reduceBtn:eq("+index+")").removeAttr("disabled");
		} else if(out_amt2 < 0) {
			out_amt2 = 0;
			$(".reduceBtn:eq("+index+")").attr("disabled", "disabled");
			$(".addBtn:eq("+index+")").removeAttr("disabled");
		} else {
			$(".addBtn:eq("+index+")").removeAttr("disabled");
			$(".reduceBtn:eq("+index+")").removeAttr("disabled");
		}
	$(".number:eq("+index+")").val(out_amt2);
	}

	function reduce(lostcount,index) {
		var out_amt2 = $(".number:eq("+index+")").val();
//		alert(out_amt2)
		out_amt2 = parseInt(out_amt2) - 1;
		if(out_amt2 < 0) {
			out_amt2 = 0;
			$(".reduceBtn:eq("+index+")").attr("disabled", "disabled");
		} else if(out_amt2 < lostcount) {

			$(".addBtn:eq("+index+")").removeAttr("disabled");
		}
		$(".number:eq("+index+")").val(out_amt2);
	}

	function add(lostcount,index) {
		var in_amt = $(".number:eq("+index+")").val();
//		alert($(".number"))
//		 var out_amt1= demo[index];
		in_amt = parseInt(in_amt) + 1;

		if(in_amt > lostcount) {
			in_amt = lostcount;
			$(".addBtn:eq("+index+")").attr("disabled", "disabled");
		} else if(in_amt > 0) {

			$(".reduceBtn:eq("+index+")").removeAttr("disabled")
		}
		$(".number:eq("+index+")").val(in_amt);
//		out_amt1.val(.number:eq("+index+"));
	}

	
    

	   function qr(rcpt_id){
			 $.ajax({
		 	type:"post",
		 	url:"shgl/mx.lgg",
		 	data:"rcpt_id="+rcpt_id,
//			dataType:"json",
		 	success:function (data) {  
		 		/* alert(data.length); */
		 	if (data.length!=0) {
		 		 alert("入库未完成");
		 		
		 	}else if (data.length==0){
		 		alert("入库完成");
		 		$.ajax({
 		         		type:"post",
 		         		url:"shgl/updat.lgg",
 		         		data:"rcpt_id="+rcpt_id,
 		         		success:function (data) { 
 		         			$("#tab").bootstrapTable("refresh");
 		         		}
 		         	});
		 	}
		 	
		 	}
			});
			
		}

    
    </script>
</head>
<body>

 <div class="x-body">
      <div class="layui-row" align="center">
        <form class="form-inline">
          <div class="form-group" align="center">	
           <select name="name" id="name" class="form-control">
       	     <option value="0">请选择</option>
	       </select>
           <button type="button" class="btn btn-default btn-md glyphicon glyphicon-search" id="btn"></button>
          </div>
        </form>
      </div>
      
      
		
    
     <div class="modal fade bs-example-modal-lg" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
     <div class="modal-dialog modal-lg" role="document" style="width:1200px">
     <div class="modal-content">
     	<div class="modal-header">
			<h4>待收货单列表</h4>			
		</div>
     	
     	
            <div class="modal-body">
					<table id="tab2"></table>		        
			</div>
			
			<div class="modal-footer ">
						<button type="button" class="btn btn-danger glyphicon glyphicon-remove" data-dismiss="modal"></button>
						<button type="button" class="btn btn-success glyphicon glyphicon-ok" ></button>
					</div>
    </div>
  </div>
</div>
    
    
    
    
    
    
      <div class="modal fade bs-example-modal-lg" id="mModal" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
     <div class="modal-dialog modal-lg" role="document" style="width:1200px">
     <div class="modal-content">
     	<div class="modal-header">
			<h4>货损情况</h4>			
		</div>
     	
     	
            <div class="modal-body">
            	
					<table id="tab4" style="text-align:center"></table>	
	                  
	                  <h4>货损列表</h4>
                    <table id="tab5"></table>
			</div>
			
			<div class="modal-footer ">
						<button type="button" class="btn btn-danger glyphicon glyphicon-remove" data-dismiss="modal"></button>
						<button type="button" class="btn btn-success glyphicon glyphicon-ok" ></button>
					</div>
    </div>
     
  </div>
</div> 
    
    
    
      <div class="modal fade bs-example-modal-lg" id="mModal1" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
     <div class="modal-dialog modal-lg" role="document" style="width:1200px">
     <div class="modal-content">
     	<div class="modal-header">
			<h4>入库货物清单</h4>			
		</div>
     	
     	
            <div class="modal-body">
					<table id="tab6"></table>
					<h4>预入库表</h4>	
					<table id="tab7"></table>		        
			</div>
			
			<div class="modal-footer">
						<button type="button" class="btn btn-danger glyphicon glyphicon-remove" data-dismiss="modal"></button>
						<button type="button" class="btn btn-success glyphicon glyphicon-ok" ></button>
					</div>
    </div>
  </div>
</div>
    
    
     
      
      </div>
      <br />
<table id="tab"></table>
</body>
</html>